﻿using NHibernate.Validator.Constraints;
using TestBat.IModels.Domain;

namespace TestBat.Models.Domain
{
    public class ScheduleTask : DomainEntity, IScheduleTask
    {
        [Range(Min = 1)]
        public virtual int Sort
        {
            get; set;
        }

        [NotNull]
        public virtual ISchedule Schedule
        {
            get { return schedule; }
            set
            {
                if (Equals(schedule, value))
                    return; // no change needed

                if (schedule != null)
                    schedule.Tasks.Remove(this); // remove from old schedule

                schedule = value;

                if (schedule != null)
                    schedule.Tasks.Add(this); // add to new schedule
            }
        }

        [NotNull]
        public virtual ITask Task
        {
            get;
            set;
        }

        private ISchedule schedule;
    }
}
